#include <stdio.h>
#include <stdlib.h>
#include<windows.h> 
#include <math.h>
#define ElementType int
typedef struct{
    ElementType data;
    struct node *lchild,*rchild;
}BiTNode,*BiTree;
//打印二叉树的形状
void gotoxy(int x, int y) { //光标定位到指定列行
	COORD c; 
	c.X = x -1; 
	c.Y = y -1; 
	SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); } 

void DisplayBinTree(BiTree T,int col,int row,int h) 
{ 
	if (T)
	{ gotoxy(col,row);//光标定位到col列row 行
		printf("%c",T->data);
		DisplayBinTree(T->lchild,col-h,row+1,h/2);
		DisplayBinTree(T->rchild,col+h,row+1,h/2);
	}
}
int GetHightOfTree(BiTree T)
{
	int rh=0,lh=0;
	if(!T)
		return 0;		
	else
	{
		lh=GetHightOfTree(T->lchild);
		rh=GetHightOfTree(T->rchild);
		return (lh>rh?lh:rh)+1;
	}
}
void DisplayTree(BiTree T)//树形结构打印二叉树
{
	int k=0;
	k=GetHightOfTree(T);
	DisplayBinTree(T, (int)(pow(2,k-1)*2+1),4,(int)pow(2,k-1)) ;
	printf("\n\n\n\n\n\n\n");
}
BiTree CreateBiTree(){
    BiTree T;
    int ch;
    scanf("%d",&ch);
    if(ch==0) T=NULL;
    else{
        T=(BiTNode *)malloc(sizeof(BiTree));
        T->data=ch;
        T->lchild=CreateBiTree();
        T->rchild=CreateBiTree();
    }
    return T;
}
void PrintTree(BiTree T){
    if(T!=NULL){
        if(T->lchild!=NULL&&T->rchild!=NULL)
        printf("%d",T->data);
        PrintTree(T->lchild);
        PrintTree(T->rchild);
    }
   
}
int MaxTree(BiTree T){
    static int max=-1000;
    if(T){
        if(max<T->data)
            max=T->data;
        MaxTree(T->lchild);
        MaxTree(T->rchild);
    }
    return max;
}
int main(){
    BiTree T;
    int max=0;
    T=CreateBiTree(T);
    DisplayTree(T);
    PrintTree(T);
    printf("%d",MaxTree(T));
}